# Maintainer (ArchLinux): Stefan Husmann <stefan-husmann@t-online.de>
# Contributor (ArchLinux): Benjamin van der Burgh <benjaminvdb@gmail.com>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=octave-hg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=r19590.6d75f1683ce8
pkgrel=1
pkgdesc="A high-level language, primarily intended for numerical computations (mingw-w64)"
url="https://www.gnu.org/software/octave/"
arch=('any')
license=('GPL')
# Some of these may be optional, e.g. arpack, lapack, qhull, but if they
# are installed, octave will be linked against them.
depends=("${MINGW_PACKAGE_PREFIX}-arpack"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-fftw>=3.2.2"
         "${MINGW_PACKAGE_PREFIX}-fltk"
         "${MINGW_PACKAGE_PREFIX}-glpk"
         "${MINGW_PACKAGE_PREFIX}-gl2ps"
         "${MINGW_PACKAGE_PREFIX}-hdf5"
         "${MINGW_PACKAGE_PREFIX}-qhull"
         "${MINGW_PACKAGE_PREFIX}-qrupdate"
         "${MINGW_PACKAGE_PREFIX}-qscintilla"
         "${MINGW_PACKAGE_PREFIX}-graphicsmagick")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran"
             'pcre'
             'mercurial'
             'git'
             'gperf'
             'rsync'
             # ArchLinux uses suitesparse-octavecompat.
             "${MINGW_PACKAGE_PREFIX}-suitesparse")
#             'transfig'
#             'epstool')
#             'texlive-core')
optdepends=('texinfo: for help-support in octave'
            'gnuplot: alternative plotting'
            'portaudio: for using audiodevinfo.oct')
conflicts=('octave')
install=octave.install
options=('!emptydirs' '!makeflags')
source=("git+https://git.savannah.gnu.org/git/gnulib.git"
#        "hg+https://hg.savannah.gnu.org/hgweb/octave"
        "https://hg.savannah.gnu.org/hgweb/octave/archive/tip.tar.bz2"
        # gnulib
        "0001-tempname.h-Rename-try-to-try_.patch"
        # octave
        "0001-Port-to-Qt5.patch"
        "0002-OCTAVE_CHECK_LIB-for-suitesparseconfig.patch")
sha256sums=('SKIP'
            'SKIP'
            '745424d2c3f91e65d0be51487f707340e2f46db5e7bc3ae509cad08dd5c699a2'
            '5aacbe79ce47654ca3953e62164fe0b6b841d5ae98400fbfd8c9230de680897b'
            'f987b2e47e0a3c1fa0e1bd2f1a0cc3f0c9ed58f82718827b08a624e039748b0c')
_hgrepo=octave
_appver=4.1.0+
provides=("${MINGW_PACKAGE_PREFIX}-octave=${_appver}")

# pkgver() {
#   cd ${srcdir}/${_hgrepo}
#   hg update > /dev/null
#   printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
# }

# perpare() {
#   cd $srcdir/${_hgrepo}
#   patch -p1 -i "${srcdir}"/0001-Port-to-Qt5.patch
# }

prepare() {
  [[ -d ${srcdir}/octave ]] && rm -rf "${srcdir}"/octave
  mv "${srcdir}"/octave-* "${srcdir}"/octave
  cd "${srcdir}"/gnulib
  patch -p1 -i "${srcdir}"/0001-tempname.h-Rename-try-to-try_.patch
  cd "${srcdir}"/octave
  patch -p1 -i "${srcdir}"/0001-Port-to-Qt5.patch
  patch -p1 -i "${srcdir}"/0002-OCTAVE_CHECK_LIB-for-suitesparseconfig.patch
  ./bootstrap --no-git --gnulib-srcdir=$srcdir/gnulib
 }

build() {
  cd "${srcdir}"
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH}
  cd build-${CARCH}
  [[ $CARCH == "x86_64" ]] && _arch=amd64
  [[ $CARCH == "i686" ]] && _arch=i386
  CPPFLAGS+=" -D_POSIX -D_POSIX_C_SOURCE " \
  "${srcdir}"/${_hgrepo}/configure \
      --prefix=${MINGW_PREFIX} \
      --enable-shared --enable-jit \
      --enable-qhull --with-umfpack \
      --with-quantum-depth=16 --disable-java
  make
}

package() {
  cd ${srcdir}/${_hgrepo}/build-${CARCH}
  make DESTDIR=${pkgdir} install
}
